<?php
class System_Form_TemplateAdd extends Promotor_Form_Scaffold {

	public function init() {
		$this->setMethod('post');
		$this->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);

		$this->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
        
		$this->addSubForm($this->_getContentForm(), 'default');
	}

	public function getValues($suppressArrayNotation = false) {
		$values = parent::getValues();

		/**
		 * Parsowanie wartości dla DbTable_Row
		 */
		list ($values['template'], $values['style']) = explode('-',$values['template']);

		return $values;
	}
	
	/**
     * Zbieranie informacji o stylach 
     */
	protected function _getTemplatesForMultiOptions()
	{
		$multiOptions = array();

		$templates = KontorX_Template::getInstance();
    	foreach ($templates->findTemplates() as $templateId => $template)
    	{
    		$styles = array();
    		foreach($templates->findStyles($templateId) as $key => $style)
    		{
    			$styles[$templateId . '-' . $key] = $style['name'];
    		}
    		$multiOptions[$templateId] = $styles;
    	}
    	
    	return $multiOptions;
	}
	
	/**
     * @return void
     */
    protected function _getContentForm() {

    	$subForm = new Zend_Form_SubForm();
    	$subForm->setAttribs(array(
    		'legend' => 'Kompozycja strony'
    	));


        $subForm
        	->addElement(
                'text',
                'name',
                array(
                    'label' => 'Nazwa kompozycji strony',
                    'required'  => true,
                	'trim' => true,
                	'propercase' => true
                )
            )
            ->addElement('select','template',
				array(
					'label'        => 'Szablon strony',
					'required'	   => true,
					'multiOptions' => $this->_getTemplatesForMultiOptions()
			    )
			)
			->addElement('select','columns',
				array(
					'label'       => 'Układ strony',
					'required'	  => true,
					'multiOptions' => array(
						'ONE' => 'Jedna kolumna (podstawowy)',
						'TWO_LEFT' => 'Kolumna z lewej',
						'TWO_RIGHT' => 'Kolumna z prawej',
						'THREE' => 'Trzy kolumny'
					)
			    )
			);
			
		return $subForm;
    }
}